#include <stdio.h>
#include <string.h>
#include <mysql/mysql.h>
#include <stdlib.h>

struct student
{
	int id;
	char name[10];
	float score;
};

int main()
{
	char sql[100] = {0};
	MYSQL *res = NULL,*con = NULL;

	con = mysql_init(NULL);

	res = mysql_real_connect(con,"localhost","root","123","company",0,NULL,0);
	if(res == NULL)
	{
		printf("%s\n",mysql_error(con));
		exit(-1);
	}

	printf("connect is success\n");


	int ret = 0;
	struct student stu;
	memset(&stu,0,sizeof(struct student));

	printf("please input id name score:\n");
	scanf("%d%s%f",&stu.id,stu.name,&stu.score);

	sprintf(sql,"insert into student values(%d,'%s',%f)",stu.id,stu.name,stu.score);

	ret = mysql_query(con,sql);
	if(ret != 0)
	{
		printf("%s\n",mysql_error(con));
		mysql_close(con);
		exit(-1);
	}




	mysql_close(con);

	return 0;
}
